/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Renderers;

import comu.Configuracio;
import entity.Collita;
import entity.Produccio;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import vistas.textImg.Textos;

/**
 *
 * @author David
 */
public class LabelRenderer_Diari extends JLabel implements ListCellRenderer {

    public LabelRenderer_Diari() {
        setOpaque(true);
        setHorizontalAlignment(LEFT);
        setVerticalAlignment(CENTER);
        setFont(Textos.FONT_GRAN);
    }

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }
        if (Produccio.class.isInstance(value)) {
            Produccio produccio = (Produccio) value;
            String out = "";
            out += Configuracio.sdf.format(produccio.getDataPlanta().getTime()) + " ";
            out += produccio.getProductesId().getNom() + " ";
            out += produccio.getQuantitat() + " " + produccio.getUnitatsMesuraId() + " ";
            out += produccio.getVarietat() + " ";
            out += produccio.getOrigen() + " ";
            //out += Textos.COLLIR_BOTO_ACABADA + ": ";
            if (produccio.getTerminado()) {
                out += "Si";
            } else {
                out += "No";
            }
            setText(out);
        } else if (Collita.class.isInstance(value)) {
            Collita collita = (Collita) value;
            String out = "";
            out += Configuracio.sdf.format(collita.getData().getTime()) + " ";
            out += collita.getQuantitat() + " " + collita.getUnitatsMesuraId() + " ";
            out += collita.getProduccioId().getProductesId().getNom() + " ";
            out += collita.getProduccioId().getCampId().getNom() + " ";
            setText(out);
        }
        return this;
    }
}
